package net.lab1024.sa.admin.module.business.quotation.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.quotation.dao.QuotationItemsDao;
import net.lab1024.sa.admin.module.business.quotation.domain.entity.QuotationItemsEntity;
import net.lab1024.sa.admin.module.business.quotation.domain.form.QuotationItemsAddForm;
import net.lab1024.sa.admin.module.business.quotation.domain.form.QuotationItemsQueryForm;
import net.lab1024.sa.admin.module.business.quotation.domain.form.QuotationItemsUpdateForm;
import net.lab1024.sa.admin.module.business.quotation.domain.vo.QuotationItemsVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * 报价明细 Service
 *
 * @Author zzx
 * @Date 2025-08-07 19:45:24
 * @Copyright zzx
 */

@Service
public class QuotationItemsService {

    @Resource
    private QuotationItemsDao quotationItemsDao;

    /**
     * 分页查询
     */
    public PageResult<QuotationItemsVO> queryPage(QuotationItemsQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<QuotationItemsVO> list = quotationItemsDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(QuotationItemsAddForm addForm) {
        QuotationItemsEntity quotationItemsEntity = SmartBeanUtil.copy(addForm, QuotationItemsEntity.class);
        quotationItemsDao.insert(quotationItemsEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(QuotationItemsUpdateForm updateForm) {
        QuotationItemsEntity quotationItemsEntity = SmartBeanUtil.copy(updateForm, QuotationItemsEntity.class);
        quotationItemsDao.updateById(quotationItemsEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        quotationItemsDao.batchUpdateDeleted(idList, true);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long quotationItemId) {
        if (null == quotationItemId){
            return ResponseDTO.ok();
        }

        quotationItemsDao.updateDeleted(quotationItemId, true);
        return ResponseDTO.ok();
    }
}
